﻿using System.Web.UI;
using bGallery.Core.Domain;

namespace bGallery.DataSource
{
	public class CategoryData : IHierarchyData
	{
		private Category item;

		public CategoryData() { }

		public CategoryData(Category item)
		{
			this.item = item;
		}

		public IHierarchicalEnumerable GetChildren()
		{
			return new CategoryTreeDataSource(item.SubCategories);
		}

		public IHierarchyData GetParent()
		{
			return new CategoryData(item.ParentCategory);
		}

		public bool HasChildren
		{
			get { return (item.SubCategories != null); }
		}

		public string Path
		{
			get
			{
				Category cat = this.item;
				string s = this.item.Name;
				while ((cat = cat.ParentCategory) != null)
				{
					s = cat.Name + ": " + s;
				}
				return s.Trim();
			}
		}

		public object Item
		{
			get { return item; }
		}

		public string Type
		{
			get { return item.ToString(); }
		}
	}
}